<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字</title>
</head>
<body>
<input type="text" placeholder="请输入0-100之间的整数" id="i1">
<input type="button" value="猜一猜" onclick="f1()">
<div>
  结果:<span></span>
</div>
<script>
  let x = parseInt(Math.random()*101);
  let a = 0;
  function f1() {
    a++;
    let i = document.querySelector("#i1");
    let s = document.querySelector("span");
    if(isNaN(i.value)) {
      s.innerText = "输入有误!";
      return;
    }
    if(i.value == x) {
      s.innerText = "恭喜你，猜对了"+" 猜了"+a+"次";
    }else if(i.value > x) {
      s.innerText = "猜大了";

    }else if(i.value < x) {
      s.innerText = "猜小了";
    }
  }
</script>

</body>
</html>